package com.xca.is.repository;

import com.xca.is.entity.Wallpaper;
import com.xca.is.service.WallpaperService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class WallpaperRepository {
    private static final String URL = "https://api.yuqios.com/" ;
    private WallpaperService service ;

    public WallpaperRepository(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URL)
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build() ;
        service = retrofit.create(WallpaperService.class) ;
    }

    public Observable<Wallpaper> getData(int type , int page){
        return service.getData(type,page)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io()) ;
    }
}
